package org.example.text;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;
import java.util.Set;

/**
 * @Auther:Liu
 * @Testname:SetText
 * @Date:2025/8/12 9:23
 */
@SpringBootTest
@Slf4j
public class SetText {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void a() {
        SetOperations<String, String> ops = stringRedisTemplate.opsForSet();
        ops.add("A","1","2","3","4","5","6","7","8","9");
        ops.add("B","87","2","3","4","5","6","7","8","12");
    }


    @Test
    public void b() {
        SetOperations<String, String> ops = stringRedisTemplate.opsForSet();
        Set<String> all = ops.members("A");
        log.info("all: {}", all);
        String randomMember = ops.randomMember("A");
        log.info("randomMember: {}", randomMember);
        List<String> randomMembers = ops.randomMembers("A",4);
        log.info("randomMembers: {}", randomMembers);
    }


    @Test
    public void c() {
        SetOperations<String, String> ops = stringRedisTemplate.opsForSet();
        Long size = ops.size("A");
        log.info("size: {}", size);
        Set<String> difference = ops.difference("A", "B");
        log.info("difference: {}", difference);
        Set<String> intersect = ops.intersect("B", "A");
        log.info("intersect: {}", intersect);
        Set<String> union = ops.union("A", "B");
        log.info("union: {}", union);
        List<String> a = ops.pop("A", 6);
        log.info("a: {}", a);
        List<String> b = ops.pop("B", 6);
        log.info("b: {}", b);
        Boolean b1 = ops.move("B", "1", "2");
        log.info("b1: {}", b1);
        Boolean a1 = ops.isMember("A", "7");
        log.info("a1: {}", a1);
    }
}
